<%@ taglib
		prefix="c"
		uri="http://java.sun.com/jsp/jstl/core"
%>
<%@ page
		contentType="text/html;charset=UTF-8"
		language="java"
%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" href="./layui/css/layui.css" />	
	</head>
	<body>
		<div style="width: 90%;margin: 10px auto;">
			<h1 style="text-align: center;padding: 20px;">
				欢迎使用河北地质大学新闻管理系统
			</h1>
			<div>
				<form class="layui-form layui-form-pane"
					  action="${pageContext.request.contextPath}/NewsServlet?method=query"
					  method="post">
					<div class="layui-form-item">
						
						<div class="layui-inline">
							<label class="layui-form-label">标题</label>
							<div class="layui-input-inline">
								<input class="layui-input"
									   type="text" name="title"
									   placeholder="请输入标题"
									   value=""/>
							</div>	
						</div>
					
						<div class="layui-inline">
							<label class="layui-form-label">内容</label>
							<div class="layui-input-inline">
								<input class="layui-input"
									   placeholder="请输入内容"
									   type="text"
									   name="content"
									   value="" />
							</div>	
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">分类</label>
							<div class="layui-input-inline" style="width: 300px;">
								<input class="layui-input"
									   type="text"
									   name="type"
									   placeholder="请输入分类"
									   value=""/>
							</div>	
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">发布者</label>
							<div class="layui-input-inline">
								<input class="layui-input"
									   placeholder="请输入发布者"
									   type="text"
									   name="publisher"
									   value=""/>
							</div>	
						</div>
						
						<div class="layui-inline">
							<label class="layui-form-label">发布部门</label>
							<div class="layui-input-inline">
								<input class="layui-input"
									   type="text"
									   placeholder="请输入发布部门"
									   name="department"
									   value=""/>
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline">
								<button class="layui-btn"
										lay-submit
										lay-filter="search">
									<i class="layui-icon">&#xe615;</i>
								</button>
							</div>
						</div>
					</div>
				</form>
			</div>
			<div>
				<div class="layui-form-item">
					<a class="layui-btn"
					   href="${pageContext.request.contextPath}/NewsServlet?method=addNew">
						<i class="layui-icon">&#xe654;</i>
						添加
					</a>
				</div>
			</div>
			<table class="layui-table">
				<colgroup>
					<col width="10%">
					<col width="40%">
					<col width="10%">
					<col width="10%">
					<col width="10%">
					<col width="5%">
					<col width="15%">
				</colgroup>
				<thead>
					<tr>
						<th style="text-align: center;">标题</th>
						<th style="text-align: center;">内容</th>
						<th style="text-align: center;">分类</th>
						<th style="text-align: center;">发布者</th>
						<th style="text-align: center;">部门</th>
						<th style="text-align: center;">浏览量</th>
						<th style="text-align: center;">操作</th>
					</tr>
				</thead>
				<tbody>
				<c:forEach items="${newsList}" var="news">
					<tr>
						<td style="text-align: center;">${news.title}</td>
						<td style="text-align: center;">${news.content}</td>
						<td style="text-align: center;">${news.type}</td>
						<td style="text-align: center;">${news.publisher}</td>
						<td style="text-align: center;">${news.department}</td>
						<td style="text-align: center;">${news.count}</td>
						<td style="text-align: center;display: none">${news.id}</td>
						<td style="text-align: center;">
							<a href="${pageContext.request.contextPath}/NewsServlet?method=editNew&id=${news.id}"
							   class="layui-btn layui-btn-normal layui-btn-xs">
								<i class="layui-icon">&#xe642;</i>编辑
							</a>
							<button class="layui-btn layui-btn-danger layui-btn-xs btn-del">
								<i class="layui-icon">&#xe640;</i>删除
							</button>
							<input type="hidden"
								   name="url"
								   value="" />
						</td>
					</tr>

				</c:forEach>
				</tbody>
			</table>
		</div>

		
		
		<script src="./layui/layui.js"></script>
		<script>
			window.msg = "${msg}";
			var layer;
			layui.use(['laydate', 'layer', 'form', 'jquery'], function(){
				var laydate = layui.laydate;
				layer = layui.layer;
				var form = layui.form;
				var $ = layui.jquery;
			

				//注册删除回调函数
				$('.btn-del').on('click',function(){
					
					var url = $(this).parent().children()[2].value;
					var title = $(this).parent().parent().children()[0].innerText;
					//console.log($(this).parent().parent().children()[1].innerText);
					var id = $(this).parent().parent().children()[6].innerText;
					layer.confirm('确定删除标题为[' + title +']记录', {
					  btn: ['确定', '取消'] //可以无限个按钮
					}, function(index, layero){
					  //按钮【确定】的回调
					  	layer.close(index);
						window.location="${pageContext.request.contextPath}/NewsServlet?method=del&id="+id;
					}, function(index){
					  //按钮【取消】的回调
					});
				})
				
				form.on('submit(search)',function(data){
					return true;
				});

				if(window.msg!=undefined && window.msg!=""){
					layer.msg(window.msg);
					window.msg="";
				}
			});
		</script>
	</body>
</html>
